class Solution {
public:
    int GetNumberOfK(vector<int> nums ,int target) {
        int lbound = 0, rbound = 0;
        // 寻找上界
        int l=0,r=nums.size();
        while(l<r){
            int mid=l+((r-l)>>1);//算中值
            if(nums[mid]<target)
                l=mid+1;
            else
                r=mid;
        }
        lbound=l;
        // 寻找下界
        l=0,r=nums.size();
        while(l<r){
            int mid=l+((r-l)>>1);//算中值
            if(nums[mid]<=target)
                l=mid+1;
            else
                r=mid;
        }
        rbound=l;
        return rbound - lbound;//下界-上界即为出现次数
    }
};